﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySearch;
using Kpmg.CompanyInfo;

public partial class User_CreateTicket : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string profileCode = "0";//Request["profileCode"];
            string chargeableCode = Request["chargeablecode"];
            string serviceTypeCode = "02.01";// Request["serviceTypeCode"];
            string ticketNo = Request["ticketNo"]; //"2013082700005";//"2013082700008";

            txtChargeableCode.Attributes.Add("profileCode", profileCode);


            if (!string.IsNullOrEmpty(profileCode) && !string.IsNullOrEmpty(chargeableCode) && !string.IsNullOrEmpty(serviceTypeCode))//create client ticket with profileCode and chargeableCode
            {
                Profile profile = ProfileOM.GetProfile(profileCode);
                if (profile == null)
                    Response.Redirect("~/user/CreateTickets.aspx");

                SetTicketProfile(profile, chargeableCode);
                SetPrimaryContact(profile, chargeableCode);
                SetTicketDetailsForCreate(serviceTypeCode, profileCode, chargeableCode);
            }
            else if (!string.IsNullOrEmpty(profileCode) && !string.IsNullOrEmpty(serviceTypeCode))//create non-client ticket with profileCode
            {
                Profile profile = ProfileOM.GetProfile(profileCode);
                if (profile == null)
                    Response.Redirect("~/user/CreateTickets.aspx");

                SetTicketProfile(profile, chargeableCode);
                SetTicketDetailsForCreate(serviceTypeCode, profileCode, chargeableCode);
            }
            else if (!string.IsNullOrEmpty(ticketNo))//view ticket with ticketNo
            {
                Ticket ticket = null;// TicketOM.GetTicket(ticketNo);
                if (ticket == null)
                    Response.Redirect("~/");

                Profile profile = ProfileOM.GetProfile(ticket.ProfileCode);
                if (profile == null)
                    Response.Redirect("~/");

                SetTicketProfile(profile, ticket.ChargeableCode);
                SetPrimaryContact(profile, ticket.ChargeableCode);
                SetTicketDetailsForView(ticket);
            }

            init();
            //TicketDetailForCreate.SetChargeableID("38615");
        }
    }

    protected void init()
    {
        lblProfileType.Text = "Internal";
        lblProfileDes.Text = "General";
        txtChargeable.Text = "900AA0001 - Firm Admin";
        txtProfiltCentre.Text = "950370 - KDC ITS - Local";
    }

    #region Button event

    protected void btnOpenFolder_Click(object sender, EventArgs e)
    {
        //string path = System.Configuration.ConfigurationManager.AppSettings["TicketHome"] + this.TicketNoLabel.Text
        //    + "\\" + btnDataNeeded.CommandArgument;

        //WsKdcTool.NotifyChange(this.TicketNoLabel.Text, hfCurrentIID.Value);

        //if (Directory.Exists(path))
        //{
        //    path = path.Replace("\\", "\\\\");
        //    this.lblScript.Text = "<script>window.open('" + path + "');</script>";
        //}
        //else
        //    this.lblScript.Text = "Folder not found: " + path;
    }

    protected void btnSaveDraft_Click(object sender, EventArgs e)
    {
        // var data = this.TicketDetailForCreate.GetTicketData();

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {

    }

    protected void btnReset_Click(object sender, EventArgs e)
    {

    }

    protected void btnWithDraw_Click(object sender, EventArgs e)
    {

    }

    #endregion

    #region Ticket Data

    protected void ValidateData()
    {

    }

    protected void GetTicketData()
    {

    }

    protected void BindTicketData()
    {

    }

    #endregion

    #region private

    private void SetTicketProfile(Profile profile, string chargeableCode = "" )
    { 
    }

    private void SetPrimaryContact(Profile profile, string chargeableCode)
    {
        //TicketProfileForUser.SetPrimaryContact(profile, chargeableCode);
    }

    private void SetTicketDetailsForView(Ticket ticket)
    {
        //TicketDetailForCreate.SetTicketDetailsForView(ticket);
    }

    private void SetTicketDetailsForCreate(string serviceTypeCode, string profileCode, string chargeableCode)
    {
        //TicketDetailForCreate.SetTicketDetailsForCreate(serviceTypeCode, profileCode, chargeableCode);
    }

    #endregion
}
